<?php if($creditMemoForm->isNew()):?>
  <?php $void = 'N'?>
  <div id="creditMemoPanel">
  <div class="form_title">New Credit Memo for <?php echo $contact->getListName() ?></div>
<?php else:?>
  <?php $void = $creditMemoForm->getObject()->getDocument()->getVoid()?>
  <div id="creditMemoFormDiv">
  <div class="form_title">View Credit Memo for <?php echo $contact->getListName().($void=='Y'?', CREDIT MEMO IS VOID.':''); ?></div>
<?php endif;?>
  <?php echo form_tag_for($creditMemoForm,$creditMemoForm->getUrl(),array('id'=>'creditMemoForm',))?>
    <font color="#FF0000"><?php echo $error_message?></font>
    <table>
      <tr>
        <td class="container box">
          <?php include_partial('credit_form',array('documentForm'=>$documentForm,'creditMemoForm'=>$creditMemoForm,'invoice'=>$invoice,))?>
        </td>
      </tr>
    </table>
    <?php if ($void=='N'):?>
    <center>
      <?php if(! $creditMemoForm->isNew()):?>
        <input type="button" value="Void" id="creditMemoButtonVoid"/>
        <script language="javascript">
          $(document).ready(
            function(){
              $('#creditMemoButtonVoid').click(
                function(e){
                  $.get(
                    'actionVerifier/verify',
                    {
                      'task':'creditMemoVoid',
                      'credit_iden':"<?php echo $creditMemoForm->getObject()->getCreditIden()?>",
                      'callback':'creditMemoVoidSuccess',
                      'cancel_callback':'creditMemoVoidSuccess({"credit_iden":"<?php echo $creditMemoForm->getObject()->getCreditIden()?>"},\'\')',
                      'prompt':"Void Credit Memo# <?php echo $creditMemoForm->getObject()->getCreditId()?>",
                    },
                    function(content){
                      $('#creditMemoPanel').html(content);
                    }
                  );
                }
              );
            }
          );
        </script>
      <?php else:?>
        <input type="submit" value="Save"/> |
        <input type="reset" value="Reset"/>
      <?php endif;?>
    </center>
    <?php endif;?>
  </form>
</div>


<?php if ($void=='N'):?>
<script language="javascript">
  $(document).ready(
    function(){
      $('#creditMemoForm').submit(
        function(){
          showStatusWindow();
          $(this).ajaxSubmit(
            {
              type: 'post',
              dataType: 'html',
              success: 
              function(data,statusText){
                <?php if($creditMemoForm->isNew()):?>
                $('#creditMemoPanel').html(data);
                <?php else:?>
                $('#creditMemoFormDiv').html(data);
                <?php endif;?>
                hideStatusWindow();
              },
            }
          );
          return false;
        }
      );
    }
  );
</script>
<?php endif;?>